home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / videoedt / videoedt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  25.2 KB  |  1,029 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/VideoEdit/RCS/VideoEdit.c,v 0.40 92/05/13 00:20:55 drapeau Exp $ */
  25. /* $Log:    VideoEdit.c,v $
  26.  * Revision 0.40  92/05/13  00:20:55  drapeau
  27.  * Minor change, called new function "SetPlayerHandler()" instead
  28.  * of "SetPlayer()".
  29.  * 
  30.  * Revision 0.39  92/05/12  19:04:10  drapeau
  31.  * Minor cosmetic change to the code to conform to coding style specifications.
  32.  * 
  33.  * Revision 0.38  92/01/07  14:07:24  drapeau
  34.  * Cosmetic changes only, to make code more readable.
  35.  * 
  36.  * Revision 0.37  92/01/03  15:44:36  drapeau
  37.  * Changed occurrances of "NULL" in calls to Browse() to use "0" instead.
  38.  * This is due to the ANSI definition of NULL as "(void*)0".
  39.  * 
  40.  * Revision 0.36  91/11/14  10:11:47  collab
  41.  * No code changes; only changing ownership of this file.
  42.  * 
  43.  * Revision 0.34  91/09/29  14:31:23  lim
  44.  * Removed mySerialPort.
  45.  * 
  46.  * Revision 0.33  91/09/27  16:53:10  lim
  47.  * Added "None" as default item on options Player stg.
  48.  * 
  49.  * Revision 0.32  91/09/26  11:47:55  lim
  50.  * Fixed bug in SetDuration for the case when no device has been 
  51.  * initialized.
  52.  * 
  53.  * Revision 0.31  91/09/24  21:34:20  lim
  54.  * Changed 'vEdit' to 'VideoEdit' everywhere.
  55.  * 
  56.  * Revision 0.30  91/09/04  14:01:55  lim
  57.  * Play sets paused to 0.
  58.  * 
  59.  * Revision 0.29  91/08/30  15:43:43  lim
  60.  * Check for null sender in Quit().
  61.  * 
  62.  * Revision 0.28  91/08/28  13:09:55  lim
  63.  * Corrected duration.
  64.  * 
  65.  * Revision 0.27  91/08/24  17:54:54  lim
  66.  * Implemented PrintDiagnostics. 
  67.  * Using command line flag '-d', the user can choose to launch the
  68.  * app with diagnostic messages. Otherwise, no diag messages will
  69.  * be printed.
  70.  * 
  71.  * Revision 0.26  91/08/23  17:14:52  lim
  72.  * 1. Duration can be calculated regardless of whether
  73.  * myVideo has been initialized or not.
  74.  * 2. PlayerPlay becomes PlayerForwardPlay due to change
  75.  * in 'PlayerStatus.h'
  76.  * 3. Forward and Reverse Steps both also implement still.
  77.  * 4. ClearMarker has been removed as a video object function.
  78.  * 5. Document format has been changed.
  79.  * 
  80.  * Revision 0.25  91/08/21  10:47:28  lim
  81.  * Added new variable, mySerialPort, to denote serial port setting on
  82.  * options panel. Initialized to "NOTHING".
  83.  * 
  84.  * Revision 0.24  91/08/17  20:53:05  lim
  85.  * 1. Pause After Search implemented.
  86.  * 2. OpenPanel is now Browse.
  87.  * 
  88.  * Revision 0.23  91/08/16  13:08:53  lim
  89.  * 1. No more editFilename. Filename now put in title bar. 
  90.  * 2. Call Browse() with OPENPANEL_CHECK for loading command line file.
  91.  * 3. Moved info button and function to options panel.
  92.  * 
  93.  * Revision 0.22  91/08/11  18:48:29  lim
  94.  * Replaced call to XOpenDisplay to xv_get(obj, XV_DISPLAY)
  95.  * 
  96.  * Revision 0.21  91/08/09  17:30:29  lim
  97.  * Included OpenPanel
  98.  * 
  99.  * Revision 0.20  91/08/08  17:18:44  lim
  100.  * 1. CalcSpeed() - one parameter added, 'playMode'. If playMode is 1, it is used to calculate
  101.  *    device speed for segment play. If playMode is 0, it is used to calculate device speed for
  102.  *    normal play.
  103.  * 
  104.  * Revision 0.19  91/08/07  13:18:24  lim
  105.  * 1. ErrorCheck() has been removed. The responsibility for notification of
  106.  * error has been shifted to the device drivers, which will call DisplayError()
  107.  * in 'videoObjects.c'.
  108.  * 2. Added instance pointer, "theObject" to all public function calls.
  109.  * 3. The application now sets up a device driver when started, if "vEdit.defaultPlayer"
  110.  * is set in ~/.Xdefaults.
  111.  * 
  112.  * Revision 0.18  91/08/02  12:53:28  lim
  113.  * 1. Pause() now is implemented with Still() and Play() and the
  114.  * variable 'paused'.
  115.  * 2. DevInit has been moved to the file "videoObjects.c"
  116.  * 3. allDevices has been changed from an array of device configurations
  117.  * to an array of names of devices supported.
  118.  * 
  119.  * Revision 0.17  91/07/29  22:28:58  lim
  120.  * Status codes updated to conform with specs.
  121.  * Added driver for Sony1550.
  122.  * 
  123.  * Revision 0.16  91/07/27  22:28:11  lim
  124.  * 1. Changed speed from double to int.
  125.  * 2. Added Pioneer6000Driver.
  126.  * 
  127.  * Revision 0.15  91/07/24  11:01:19  lim
  128.  * Ran through xsaber - removed redundant variables.
  129.  * 
  130.  * Revision 0.14  91/07/23  15:54:31  lim
  131.  * 1. CalcSpeed now always takes in the number of frames/sec and
  132.  * returns closest number of frames per second the device can play.
  133.  * 2. Duration rounding has been fixed.
  134.  * 3. Added Panasonic Optical Player object.
  135.  * 4. Added optionsPlayerStg to select the appropriate driver. It
  136.  * starts up with no drivers installed.
  137.  * 
  138.  * Revision 0.13  91/07/19  16:15:36  lim
  139.  * Set default value for speed in edit window to be 30.
  140.  * 
  141.  * Revision 0.12  91/07/19  14:00:13  lim
  142.  * Made changes to accommodate addition of speed field
  143.  * in edit.
  144.  * 1. SetDuration is changed so that duration depends on 
  145.  * speed to be played (depends on device).
  146.  * 2. Search is modified to fit the function prototype for
  147.  * PlayFromTo.
  148.  * Eject is now a separate button than Stop.
  149.  * PlayMode is moved to vEditEdit.c. It is no longer called
  150.  * by functions outside vEditEdit.c
  151.  * 
  152.  * Revision 0.11  91/07/17  22:49:46  lim
  153.  * Now we use Pioneer4200Pause in place of Pioneer4200Stop, because
  154.  * the latter calls puts the player into park position, which slows 
  155.  * down the TimeLine considerably the next time 'Play' is hit. Thus
  156.  * the player will always be in 'ready' state.
  157.  * 
  158.  * Revision 0.10  91/07/12  16:18:24  lim
  159.  * Initial revision implementing VideoObject.
  160.  *  */
  161.  
  162. #include "VideoEdit.h"
  163.  
  164.  
  165. static char mainrcsid[] = "$Header: /Source/Media/collab/VideoEdit/RCS/VideoEdit.c,v 0.40 92/05/13 00:20:55 drapeau Exp $";
  166.  
  167. /* Edit list variables */
  168. int lines;                                /* number of lines in the edit list */
  169. int editnum;                                /* the current selection in the edit list */
  170. int change;                                /* indicates if unsaved changes exist in the edit list */
  171. int clearframe;                                /* determines if the frame/chapter textfield is to be 
  172.                                        cleared */
  173. int search;                                /* flag to indicate if a notify procedure is to be executed
  174.                                        This is necessary because a textfield notify procedure 
  175.                                        is executed twice for each key depressed (possibly a 
  176.                                        XView bug) */
  177. int startframe[MAX_LISTSIZE]; 
  178. int endframe[MAX_LISTSIZE];                        /* arrays to store the start/end frames of each entry in the 
  179.                                        edit list */
  180. char        label[MAX_LISTSIZE][MAX_LABELSIZE+1];            /* array to store the label of each entry in the edit list */
  181. enum AudioType    audioStg[MAX_LISTSIZE];                    /* array to store audio settings for each entry */
  182. int        speedStg[MAX_LISTSIZE];                    /* array to store speed settings for each entry */
  183. Xv_font*    font;                            /* Font used in the panel list */
  184.  
  185. /* Command line variables */
  186. int receiverPort;                            /* Command line receiver port */
  187. char* startFilename;                                    /* Name of file in command line */
  188. char hostname[MAX_HOSTNAME];                        /* Name of host */
  189.  
  190. /* Player status variables */
  191. VideoObject* myVideo;                            /* Current video object */
  192. char deviceName[MaxNameLength];                        /* Name of device currently used */
  193. enum Direction skipDir = Reverse;                    /* flag to indicate which direction to skip */
  194. int paused = 0;                                /* Indicates if player is paused. */
  195. int hitQuit = 0;                            /* Set when Quit button is hit. */
  196.  
  197. enum Boolean diagMode = No;                        /* Flag to print out diagnostic messages */
  198.  
  199. /*
  200.  * Instance XV_KEY_DATA key.  An instance is a set of related
  201.  * user interface objects.  A pointer to an object's instance
  202.  * is stored under this key in every object.  This must be a
  203.  * global variable.
  204.  */
  205. Attr_attribute    INSTANCE;
  206.  
  207.  
  208. /* ERROR CHECKING ROUTINES */
  209.  
  210.  
  211. /* check if a selection is valid */
  212. int
  213. CheckSelection(start, end)
  214.      int start;
  215.      int end;
  216. {
  217.   char buf[50];
  218.  
  219.   if (start > end) 
  220.   {
  221.     DisplayError("Invalid current selection:",
  222.          "Start frame is greater than end frame.");
  223.     return -1;
  224.   }
  225.   if ((start < 1) || (end < 1)) 
  226.   {
  227.     DisplayError("Frame number must be at least 1", " ");
  228.     return -1;
  229.   }
  230.   if ((start > MAX_FRAME) || (end > MAX_FRAME)) 
  231.   {
  232.     sprintf (buf, "Maximum frame number allowed is %d\n", MAX_FRAME);
  233.     DisplayError(buf, " ");
  234.     return -1;
  235.   }
  236.   return 0;
  237. }
  238.  
  239. /*
  240.  * This function parses the command line and retrieves all the known options and their arguments.
  241.  * Currently, the two options are hostname and portnumber.
  242.  * After parsing the options, the variable optind will point to the start of those non-option arguments.  
  243.  * In this case, it will be the filename to be loaded.  At present, only one filename will be handled.  So if
  244.  * there are multiple filenames typed, the last one will be loaded.
  245.  */
  246. void CheckOptions(argc, argv)
  247.      int     argc;
  248.      char     **argv;
  249. {
  250.   int optionChar;  
  251.   int option_index = 0;
  252.   static struct option long_options[] =
  253.   {
  254.     {"hostname", 1, 0, 'h'},
  255.     {"portnumber", 1, 0, 'p'},
  256.     {"diagnostics", 0, 0, 'd'},
  257.     {0, 0, 0, 0}
  258.   };
  259.  
  260.   while (1)                                /* Start parsing all known options */
  261.   {
  262.     optionChar = getopt_long_only (argc, argv, "h:p:d:",
  263.                   long_options, &option_index);
  264.     if (optionChar == EOF)                        /* Done with all known options */
  265.     {
  266.       break;
  267.     }
  268.     switch (optionChar)
  269.     {
  270.      case 'h':
  271.       if (optarg) 
  272.       {
  273.     strcpy (hostname, optarg);
  274.       }
  275.       break;
  276.      case 'p':
  277.       if (optarg) 
  278.       {
  279.     receiverPort = atoi(optarg);
  280.       }
  281.       break;
  282.      case 'd':
  283.       diagMode = Yes;                            /* We want to print diagnostics */
  284.       break;
  285.      default:
  286.       break;
  287.     }
  288.   }
  289.   if (optind < argc)                            /* Check if a filename has been specified */
  290.   {
  291.     startFilename = (char *) malloc (256);
  292.     strcpy (startFilename, argv[optind]);
  293.   }
  294. }
  295.    
  296.  
  297. /* GENERAL PROCEDURES USED BY THE FUNCTIONS */
  298.  
  299. /*  Procedure to display the approximate duration of the current selection */
  300. void
  301. SetDuration()
  302. {
  303.   int start;
  304.   int end;
  305.   int duration;
  306.   int speedInDevice;
  307.   int speedInFrames;
  308.   char buf[80];
  309.   
  310.   start = xv_get(VideoEdit_editPopup->editStartTxt, 
  311.          PANEL_VALUE);
  312.   end = xv_get(VideoEdit_editPopup->editEndTxt, 
  313.            PANEL_VALUE);
  314.   if (start >= end) 
  315.   {
  316.     duration = 0;
  317.   }
  318.   else 
  319.   {
  320.     speedInFrames = (int) xv_get(VideoEdit_editPopup->editSpeedTxt,
  321.                     PANEL_VALUE);
  322.     if (myVideo)
  323.     {
  324.       speedInDevice = DevCalcSpeed(myVideo, speedInFrames, 1);
  325.       
  326.       if ((speedInDevice) && (end - start))
  327.     duration = (((end - start)%speedInDevice)/speedInDevice > 0.5 ? 
  328.             ((end - start)/speedInDevice +1) : (end - start)/speedInDevice);
  329.       else
  330.     duration = 0;
  331.     }
  332.     else
  333.     {
  334.       if ((speedInFrames) && (end - start))
  335.     duration = ((end - start)/speedInFrames +1);
  336.       else
  337.     duration = 0;
  338.     }      
  339.   }
  340.   sprintf (buf, "%d", duration);
  341.   xv_set(VideoEdit_editPopup->editDurTxt, 
  342.      PANEL_VALUE, buf, 
  343.      NULL);
  344.   return;
  345.   
  346. }
  347.  
  348.  
  349. /*      REMOTE CONTROLLER FUNCTIONS    */
  350.  
  351. /* accept number input using the mouse.  The current value on the textfield is
  352.    shifted to the left as input is made (if 5 digits are exceeded) */
  353. void
  354. Num(n)
  355.      int n;
  356. {
  357.   int value;
  358.   
  359.   if (clearframe) xv_set(VideoEdit_window1->frameTxt, 
  360.              PANEL_VALUE, 0,
  361.              NULL);
  362.   clearframe = 0;
  363.   value = xv_get(VideoEdit_window1->frameTxt, PANEL_VALUE);
  364.   value = value*10 + n;
  365.   if (value > 99999) value = value % 100000;                /* remove most significant digit */
  366.   xv_set (VideoEdit_window1->frameTxt, 
  367.       PANEL_VALUE, value, 
  368.       NULL);
  369. }
  370.  
  371. /*
  372.   Button notify proc to open the options popup window (optionsButton)
  373.  */
  374. void
  375. Options(item, event)
  376.      Panel_item      item;
  377.      Event           *event;
  378. {
  379.   xv_set(VideoEdit_optionsPopup->optionsPopup, 
  380.      FRAME_CMD_PUSHPIN_IN, TRUE, 
  381.      NULL);
  382.   xv_set(VideoEdit_optionsPopup->optionsPopup, 
  383.      XV_SHOW, TRUE, 
  384.      NULL);
  385. }
  386.  
  387. /*
  388.   Button notify proc to open the edit popup window (editButton)
  389.  */
  390. void
  391. Edit(item, event)
  392.      Panel_item      item;
  393.      Event           *event;
  394. {
  395.   xv_set(VideoEdit_editPopup->editPopup, 
  396.      FRAME_CMD_PUSHPIN_IN, TRUE, 
  397.      NULL);
  398.   xv_set(VideoEdit_editPopup->editPopup, 
  399.      XV_SHOW, TRUE, 
  400.      NULL);
  401. }
  402.  
  403.  
  404. /*
  405.  * Notify callback function for `stopButton'.
  406.  * Stop function
  407.  */
  408. void
  409. Stop(item, event)
  410.      Panel_item    item;
  411.      Event      *event;
  412. {
  413.   DevStop(myVideo);
  414. }
  415.  
  416.  
  417. /*
  418.  * Notify callback function for `ejectButton'.
  419.  */
  420. void
  421. Eject(item, event)
  422.      Panel_item    item;
  423.      Event        *event;
  424. {
  425.   DevEject(myVideo);
  426. }
  427.  
  428.  
  429. /*
  430.  * Notify callback function for `searchButton'.
  431.  * Search frame/chapter
  432.  */
  433. void
  434. Search(item, event)
  435.      Panel_item    item;
  436.      Event        *event;
  437. {
  438.   int searchNum;
  439.   int searchType;
  440.   
  441.   searchNum = xv_get(VideoEdit_window1->frameTxt, PANEL_VALUE);
  442.   if (CheckSelection (searchNum, MAX_FRAME) == -1) 
  443.   {
  444.     clearframe = 1;
  445.     return;
  446.   }
  447.                                       
  448.   searchType =                                /* check if addressing mode is frame or chapter */
  449.     xv_get(VideoEdit_optionsPopup->optionsSearchStg, PANEL_VALUE);
  450.  
  451.   if (searchType)
  452.     DevSetAddMode(myVideo, PlayerChapterMode);
  453.   else
  454.     DevSetAddMode(myVideo, PlayerFrameMode);
  455.   
  456.   DevPlayFromTo(myVideo, searchNum, searchNum, 30);                
  457.   clearframe = 1;
  458.   
  459. }
  460.  
  461. /*
  462.  * Notify callback function for `frameTxt'.
  463.  * Textfield for entering the frame/chapter number for searching and also for
  464.  * displaying the current frame/chapter number if so desired. 
  465.  */
  466. Panel_setting
  467. SearchKbd(item, event)
  468.      Panel_item      item;
  469.      Event           *event;
  470. {
  471.   int n;
  472.   int value;
  473.   
  474.   /* If return key is pressed, go to search mode */
  475.  
  476.   if (event_action(event) == '\r') 
  477.   {
  478.     if (search == 0)
  479.     {
  480.       Search(item, event);
  481.       search = 1;
  482.     }
  483.     else search = 0;
  484.     return PANEL_NONE;
  485.   }
  486.   
  487.   
  488.   if ((clearframe) && (search == 0) && !event_is_button(event))
  489.     xv_set(VideoEdit_window1->frameTxt, 
  490.        PANEL_VALUE, 0, 
  491.        NULL);
  492.   
  493.   /* This code segment allows the current value to be shifted left as new input is entered */
  494.  
  495.   if ((event_action(event) >= '0') || (event_action(event) <= '9')) 
  496.   {
  497.     clearframe = 0;
  498.     if (event_is_button(event)) return PANEL_NONE;
  499.     if (search == 0) 
  500.     {
  501.       n = event_action(event) - '0';
  502.       value = xv_get(VideoEdit_window1->frameTxt, PANEL_VALUE);
  503.       value = value*10 + n;
  504.       if (value > 99999) value = value % 100000;            /* remove most significant digit */
  505.       xv_set (VideoEdit_window1->frameTxt, 
  506.           PANEL_VALUE, value, 
  507.           NULL);
  508.       search = 1;
  509.     }
  510.     else search = 0;
  511.   }
  512.   return PANEL_NONE;
  513. }
  514.  
  515.  
  516. /* The following 10 procedures are the notify procedures for the numeric
  517.    key-pad */
  518.  
  519. void
  520. One(item, event)
  521.      Panel_item    item;
  522.      Event        *event;
  523. {
  524.   
  525.   Num(1);
  526. }
  527.  
  528. void
  529. Two(item, event)
  530.      Panel_item    item;
  531.      Event        *event;
  532. {
  533.   Num(2);
  534. }
  535.  
  536. void
  537. Three(item, event)
  538.      Panel_item    item;
  539.      Event        *event;
  540. {
  541.   Num(3);
  542. }
  543.  
  544. void
  545. Four(item, event)
  546.      Panel_item    item;
  547.      Event        *event;
  548. {
  549.   Num(4);
  550. }
  551.  
  552. void
  553. Five(item, event)
  554.      Panel_item    item;
  555.      Event        *event;
  556. {
  557.   Num(5);
  558. }
  559.  
  560. void
  561. Six(item, event)
  562.      Panel_item    item;
  563.      Event        *event;
  564. {
  565.   Num(6);
  566. }
  567.  
  568. void
  569. Seven(item, event)
  570.      Panel_item    item;
  571.      Event        *event;
  572. {
  573.   Num(7);
  574. }
  575.  
  576. void
  577. Eight(item, event)
  578.      Panel_item    item;
  579.      Event        *event;
  580. {
  581.   Num(8);
  582. }
  583.  
  584. void
  585. Nine(item, event)
  586.      Panel_item    item;
  587.      Event        *event;
  588. {
  589.   Num(9);
  590. }
  591.  
  592.  
  593. void
  594. Zero(item, event)
  595.      Panel_item    item;
  596.      Event        *event;
  597. {
  598.   Num(0);
  599. }
  600.  
  601.  
  602. /*
  603.  * Notify callback function for `currFrameButton'.
  604.  * Gives the current frame/chapter number.
  605.  */
  606. void
  607. CurrentFrame(item, event)
  608.      Panel_item    item;
  609.      Event        *event;
  610. {
  611.   int current;
  612.   int value;
  613.   
  614.   /* check to see if frame or chapter is desired */
  615.   value = xv_get(VideoEdit_optionsPopup->optionsSearchStg, 
  616.          PANEL_VALUE);
  617.   if (value == 0) 
  618.     current = DevQueryFrame(myVideo);
  619.   else
  620.     current = DevQueryChapter(myVideo);
  621.  
  622.   if (current >= 0)
  623.     xv_set (VideoEdit_window1->frameTxt, 
  624.         PANEL_VALUE, current, 
  625.         NULL);
  626.  
  627.   clearframe = 1;
  628. }
  629.  
  630. /*
  631.  * Notify callback function for `scanRevButton'.
  632.  * Scan backwards about 1000 frames
  633.  */
  634. void
  635. ScanReverse(item, event)
  636.      Panel_item      item;
  637.      Event           *event;
  638. {
  639.   DevReverse(myVideo);
  640. }
  641.  
  642. /*
  643.  * Notify callback function for `scanFwdButton'.
  644.  * Scan forward about 1000 frames
  645.  */
  646. void
  647. ScanForward(item, event)
  648.      Panel_item      item;
  649.      Event           *event;
  650. {
  651.   DevFastForward(myVideo);
  652. }
  653.  
  654.  
  655. /*
  656.  * Notify callback function for `playButton'.
  657.  * Play
  658.  */
  659. void
  660. Play(item, event)
  661.      Panel_item    item;
  662.      Event        *event;
  663. {
  664.   DevPlay(myVideo);
  665.   paused = 0;
  666. }
  667.  
  668. /*
  669.  * Notify callback function for `revSkipButton'.
  670.  * Skip back to the beginning of the current chapter
  671.  */
  672. void
  673. ReverseSkip(item, event)
  674.      Panel_item    item;
  675.      Event        *event;
  676. {
  677.   
  678.   int currentChapter;
  679.   int value;
  680.   int status;
  681.   
  682.   status = DevQueryStatus(myVideo);
  683.   
  684.  /* find current chapter number */
  685.  
  686.   currentChapter = DevQueryChapter(myVideo);
  687.   if (currentChapter == -1) return;
  688.  
  689.   DevSetAddMode(myVideo, PlayerChapterMode);
  690.   if (skipDir == Reverse)
  691.   {
  692.     DevPlayFromTo(myVideo, currentChapter, currentChapter,  30);        /* Implements a search */
  693.   }
  694.   else 
  695.   {
  696.     skipDir = Reverse;
  697.     DevPlayFromTo(myVideo, currentChapter+1, currentChapter+1,  30);
  698.   }
  699.   
  700.   if (status == PlayerForwardPlay) DevPlay(myVideo);
  701.   
  702.   /* check if necessary to change back mode to frame */
  703.  
  704.   value = xv_get(VideoEdit_optionsPopup->optionsSearchStg, 
  705.          PANEL_VALUE);
  706.   if (value == 0)
  707.     DevSetAddMode(myVideo, PlayerFrameMode);
  708.   
  709. }
  710.  
  711. /*
  712.  * Notify callback function for `fwdSkipButton'.
  713.  * Skip to the next chapter
  714.  */
  715. void
  716. ForwardSkip(item, event)
  717.      Panel_item    item;
  718.      Event        *event;
  719. {
  720.   skipDir = Forward;
  721.   ReverseSkip(item, event);
  722. }
  723.  
  724.  
  725. /*
  726.  * Notify callback function for `pauseButton'.
  727.  * Puts the player into still mode on first call. 
  728.  * On second call, the player goes back into playback mode.
  729.  */
  730. void
  731. Pause(item, event)
  732.      Panel_item    item;
  733.      Event        *event;
  734. {
  735.   if (paused)
  736.   {
  737.     DevPlay(myVideo);
  738.     paused = 0;
  739.   }
  740.   else
  741.   {
  742.     DevStill(myVideo);    
  743.     paused = 1;
  744.   }
  745.  
  746. }
  747.  
  748.  
  749. /*
  750.  * Notify callback function for `revStepButton'.
  751.  * Also implements still.
  752.  */
  753. void
  754. ReverseStep(item, event)
  755.      Panel_item    item;
  756.      Event        *event;
  757. {
  758.   DevStill(myVideo);
  759.   DevStep(myVideo, Reverse);
  760. }
  761.  
  762.  
  763. /*
  764.  * Notify callback function for `fwdStepButton'.
  765.  * Also implements still.
  766.  */
  767. void
  768. ForwardStep(item, event)
  769.      Panel_item    item;
  770.      Event        *event;
  771. {
  772.   DevStill(myVideo);
  773.   DevStep(myVideo, Forward);
  774. }
  775.  
  776.  
  777. /*
  778.  * Notify callback function for `speedSlider'.
  779.  * To control multi-speed play
  780.  */
  781. void
  782. Speed(item, value, event)
  783.      Panel_item      item;
  784.      int             value;
  785.      Event           *event;
  786. {
  787.   char s[5];
  788.   static int oldspeed;
  789.   enum Direction direction;
  790.   int framesPerSecond;
  791.   
  792.   oldspeed = 0;
  793.   direction = Forward;
  794.  
  795.   /* put in still mode if mouse button is up */
  796.  
  797.   if (event_is_up(event)) 
  798.   {
  799.     oldspeed = 0;
  800.     xv_set(item, PANEL_VALUE, 0, NULL);
  801.     xv_set(VideoEdit_window1->speedTxt, PANEL_VALUE, " ", NULL);
  802.     DevStill(myVideo);
  803.     return;
  804.   }
  805.   
  806.   /* check if forward or reverse play */
  807.   
  808.   if (value < 0) 
  809.   {
  810.     s[0] = '-';
  811.     value = -value;
  812.     direction = Reverse;
  813.   }
  814.   else 
  815.     s[0] = ' ';
  816.   
  817.   framesPerSecond = DevCalcSpeed(myVideo, value, 0);
  818.   sprintf (&s[1], "%d", framesPerSecond);
  819.   
  820.   if ((framesPerSecond != oldspeed) && (framesPerSecond))
  821.   {
  822.     oldspeed = value;
  823.     xv_set(VideoEdit_window1->speedTxt, 
  824.        PANEL_VALUE, s, 
  825.        NULL);
  826.     DevPlayAtSpeedDir(myVideo, framesPerSecond, direction);
  827.   }
  828. }
  829.  
  830.  
  831.  
  832. /*
  833.  * Notify callback function for `quitButton'.
  834.  * Quit from the whole program
  835.  */
  836. void
  837. Quit(item, event)
  838.      Panel_item    item;
  839.      Event        *event;
  840. {
  841.   int result;
  842.   
  843.   hitQuit = 1;
  844.   
  845.   /* check if unsaved changes exist in edit list */
  846.   if ((change) && (lines > 0)) 
  847.   {
  848.     result = notice_prompt(VideoEdit_window1->window1, NULL,
  849.                NOTICE_MESSAGE_STRINGS,
  850.                "Unsaved changes exist in the edit list.",
  851.                "Go ahead and quit? ",
  852.                NULL,
  853.                NOTICE_BUTTON_NO,    "Yes",            /* the labels are inverted to set the default to NO */
  854.                NOTICE_BUTTON_YES,    "No",
  855.                NULL);
  856.     if (result == NOTICE_YES)
  857.     {
  858.       hitQuit = 0;
  859.       return;
  860.     }
  861.     
  862.   }
  863.  
  864.   if (sender)
  865.     SenderDisconnectFromPortMgr(sender,&(receiver->receivePort));
  866.   xv_destroy_safe(VideoEdit_window1->window1);
  867. }
  868.  
  869.  
  870. /* FUNCTIONS FOR INFO POPUP WINDOW */
  871. /*
  872.  * Notify callback function for `infoOKButton'.
  873.  * Close the info popup window
  874.  */
  875. void
  876. InfoDone(item, event)
  877.      Panel_item      item;
  878.      Event           *event;
  879. {
  880.   xv_set(VideoEdit_infoPopup->infoPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  881.   xv_set(VideoEdit_infoPopup->infoPopup, XV_SHOW, FALSE, NULL);
  882. }
  883.  
  884.  
  885. #ifdef MAIN
  886.  
  887. void
  888. main(argc, argv)
  889.      int    argc;
  890.      char    **argv;
  891. {
  892.   Rect  tempRect;
  893.   int i;
  894.   int value;
  895.   Display* display;
  896.   char* defaultPlayer;
  897.    
  898.   /* Initialize XView. */ 
  899.  
  900.   xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);
  901.   INSTANCE = xv_unique_key();
  902.   
  903.   /* Command line parsing */
  904.  
  905.   strcpy(hostname, "localhost");
  906.   startFilename = NULL;
  907.   receiverPort = AnyPort;
  908.   CheckOptions(argc, argv);
  909.   
  910.   /* Initialize user interface components. */
  911.   
  912.   VideoEdit_window1 = VideoEdit_window1_objects_initialize(NULL, NULL);
  913.   VideoEdit_optionsPopup = VideoEdit_optionsPopup_objects_initialize(NULL, VideoEdit_window1->window1);
  914.   VideoEdit_editPopup = VideoEdit_editPopup_objects_initialize(NULL, VideoEdit_window1->window1);
  915.   VideoEdit_previewPopup = VideoEdit_previewPopup_objects_initialize(NULL, VideoEdit_window1->window1);
  916.   VideoEdit_infoPopup = VideoEdit_infoPopup_objects_initialize(NULL, VideoEdit_window1->window1);
  917.  
  918.   /* Initialize position of main window */
  919.  
  920.   frame_get_rect(VideoEdit_window1->window1,&tempRect);        /* Get the size of the top-level window */
  921.   tempRect.r_top = 250;
  922.   tempRect.r_left = 200;
  923.   frame_set_rect(VideoEdit_window1->window1,&tempRect);        /* Set the position of the top-level window */
  924.     
  925.   
  926.   /* Initialize position of other windows */
  927.   
  928.   xv_set(VideoEdit_optionsPopup->optionsPopup, 
  929.      XV_X, 200,
  930.      XV_Y, 50,
  931.      NULL);
  932.   xv_set(VideoEdit_editPopup->editPopup, 
  933.      XV_X, 450,
  934.      XV_Y, 250,
  935.      FRAME_DONE_PROC, EditDone,
  936.      NULL);
  937.   xv_set(VideoEdit_previewPopup->previewPopup, 
  938.      XV_X, 850,
  939.      XV_Y, 525,
  940.      NULL);
  941.   xv_set(VideoEdit_infoPopup->infoPopup, 
  942.      XV_X, 200,
  943.      XV_Y, 250,
  944.      NULL);
  945.  
  946.   /* Initialize other window attributes */
  947.  
  948.   if (startFilename)                            /* Load file at start-up if included in command line */
  949.     Browse(startFilename, BrowseCheckOpen, 0,
  950.        "#Video Edit Document#", "VideoEdit");                
  951.          
  952.   xv_set(VideoEdit_window1->window1, 
  953.      FRAME_LEFT_FOOTER, "Display : On",
  954.      FRAME_RIGHT_FOOTER, "Audio : Stereo",
  955.      NULL);
  956.   xv_set(VideoEdit_optionsPopup->optionsAudioStg,            /* Set audio to stereo */
  957.      PANEL_VALUE, 3, 
  958.      NULL);
  959.   xv_set(VideoEdit_optionsPopup->optionsDisplayStg,            /* Set address display to on */
  960.      PANEL_VALUE, 1, 
  961.      NULL);
  962.   xv_set(VideoEdit_window1->speedSlider,                
  963.      PANEL_NOTIFY_LEVEL, PANEL_ALL, 
  964.      NULL); 
  965.   xv_set(VideoEdit_previewPopup->previewPlayFirstTxt,            /* Set number of seconds to be previewed */
  966.      PANEL_VALUE, 4,                        /* to 4 */
  967.      NULL);
  968.   xv_set(VideoEdit_previewPopup->previewPlayLastTxt, 
  969.      PANEL_VALUE, 4, 
  970.      NULL);
  971.   xv_set(VideoEdit_editPopup->editModButton,                /* set modify, delete buttons to inactive */
  972.      PANEL_INACTIVE, TRUE, 
  973.      NULL);
  974.   xv_set(VideoEdit_editPopup->editDelButton, 
  975.      PANEL_INACTIVE, TRUE, 
  976.      NULL);
  977.   xv_set(VideoEdit_editPopup->editSpeedTxt,                /* set speed text to 30 */
  978.      PANEL_VALUE, 30, 
  979.      NULL);
  980.  
  981.   font = (Xv_font *)xv_find(VideoEdit_editPopup->editPopup,        /* Set font for the panel list */
  982.                 FONT,
  983.                 FONT_FAMILY, FONT_FAMILY_LUCIDA_FIXEDWIDTH,
  984.                 FONT_STYLE,  FONT_STYLE_NORMAL,
  985.                 FONT_SIZE, 12,
  986.                 NULL);
  987.   
  988.   InitNetwork(hostname);                        /* Set up protocol sender/receiver */
  989.  
  990.   display =  (Display*) xv_get(VideoEdit_window1->window1, XV_DISPLAY);
  991.   defaultPlayer = XGetDefault(display, "VideoEdit", "defaultPlayer");
  992.  
  993.   xv_set(VideoEdit_optionsPopup->optionsPlayerStg, 
  994.      PANEL_NCHOICES, numDevices, NULL);
  995.  
  996.   value = 0;
  997.   for (i=1; i < numDevices+1; i++)
  998.   {
  999.     xv_set(VideoEdit_optionsPopup->optionsPlayerStg,
  1000.        PANEL_CHOICE_STRING, i, allDevices[i-1], 
  1001.        NULL);
  1002.     if (defaultPlayer)
  1003.       if (strcmp(defaultPlayer, allDevices[i-1]) == 0)
  1004.     value = i+1;
  1005.   }
  1006.  
  1007.   if (value)
  1008.     xv_set(VideoEdit_optionsPopup->optionsPlayerStg,            /* Set player setting to default player */
  1009.        PANEL_VALUE, value-1,
  1010.        NULL);
  1011.    
  1012.   if (defaultPlayer)
  1013.     SetPlayerHandler(NULL, NULL);                /* Set up default player */
  1014.   else
  1015.     Options(NULL, NULL);                        /* Show options popup */
  1016.   
  1017.   CreateBrowse(OpenHandler, SaveHandler, 
  1018.           VideoEdit_window1->window1);                /* Set up Open Panel */
  1019.  
  1020.   xv_main_loop(VideoEdit_window1->window1);                /* Turn control over to XView */
  1021.   
  1022.   if (!hitQuit)                                /* If used 'quit' on frame menu, call Quit */
  1023.     Quit(NULL, NULL);                            /* to simulate hitting Quit button. */
  1024.   
  1025.   exit(0);
  1026. }
  1027.  
  1028. #endif
  1029.